import pygame

class MiniMap():
    
    ship_list = None
    size = [150,150]
    topleft = [20,20]
    
    def __init__(self, ship_list):
        self.ship_list = ship_list
        
    def draw(self, view_port):
        # Draw black background and edge
        pygame.draw.rect( view_port.screen, (0,0,0), ((20,20),self.size) )
        pygame.draw.rect( view_port.screen, (255,255,255), ((20,20),self.size), 2 )
        
        # Translate form actual position, to minimap position
        factor_x = self.size[0] / view_port.map_size[0]
        factor_y = self.size[1] / view_port.map_size[1]  
        
        # Draw viewport on minimap, why must there be a minus here?
        left = round( - view_port.topleft[0] * factor_x + self.topleft[0] )
        top  = round( - view_port.topleft[1] * factor_y + self.topleft[1] ) 
        width  = round( 1024 * factor_x )
        height = round( 768 * factor_y )
        rect = (left,top,width,height)
        pygame.draw.rect( view_port.screen, (0,255,0), rect, 1 )
        
        # Draw a dot for every hostile ship
        for ship in self.ship_list:
            pos_x = round( ship.position[0] * factor_x + self.topleft[0] )
            pos_y = round( ship.position[1] * factor_y + self.topleft[1] )
            pygame.draw.rect( view_port.screen, (255,0,0), (pos_x,pos_y,2,2) )
        